package com.fzk.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzk.blog.bean.DicType;
import com.fzk.blog.bean.vo.DicInfo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author fzk
 * @date 2021-08-15 16:07
 */
public interface DicTypeMapper extends BaseMapper<DicType> {
    @Select("SELECT t.id dicTypeId,v.id dicValueId,t.name dicTypeName,t.description dicTypeDescription,v.name dicValueName,v.value value " +
            "   FROM tbl_dic_type t LEFT JOIN tbl_dic_value v ON (t.id=v.dic_type_id AND v.flag=0) " +
            "   WHERE t.flag=0 " +
            "   ORDER BY dicTypeId,dicValueId,value;")
    List<DicInfo> getDicInfoList();

    @Select("SELECT t.id dicTypeId,v.id dicValueId,t.name dicTypeName,t.description dicTypeDescription,v.name dicValueName,v.value value " +
            "   FROM tbl_dic_type t LEFT JOIN tbl_dic_value v ON (t.id=v.dic_type_id AND v.flag=0) " +
            "   WHERE t.flag=0 AND t.id=#{id} " +
            "   ORDER BY dicValueId,value;")
    List<DicInfo> getDicInfoByTypeId(int id);

    @Select("select * from tbl_dic_type where name=#{name} and flag=0")
    List<DicType> selectByName(String name);

    @Select("SELECT t.id dicTypeId,v.id dicValueId,t.name dicTypeName,t.description dicTypeDescription,v.name dicValueName,v.value value " +
            "   FROM tbl_dic_type t LEFT JOIN tbl_dic_value v ON (t.id=v.dic_type_id AND v.flag=0) " +
            "   WHERE t.flag=0 AND t.name=#{dicTypeName} " +
            "   ORDER BY dicValueId,value;")
    List<DicInfo> getDicInfoByTypeName(String dicTypeName);
}
